#include <cstdio>
#include <cstring>
constexpr int Mod = 1e9 + 7;
constexpr int MaxL = 1e7 + 5;
int list_1[MaxL];
long long n;
inline int gm(long long x)
{
    if (x == 0)
    {
        return 0;
    }
    int k[10];
    memset(k, 0, sizeof(k));
    for (; x != 0;)
    {
        k[x % 10]++;
        x /= 10;
    }
    int r = 0;
    for (int i = 0; i < 10; i++)
    {
        if (k[i] >= k[r])
        {
            r = i;
        }
    }
    return r;
}
void solve()
{
    scanf("%lld", &n);
    if (n <= 1e7)
    {
        printf("%d\n", list_1[n]);
        return;
    }
    long long answer = 0;
    printf("%lld\n", answer);
}
int main()
{
    freopen("give.in", "r", stdin);
    freopen("give.out", "w", stdout);
    int answer = 0;
    for (long long int i = 1; i <= 1e7; i++)
    {
        answer += gm(i);
        if (answer >= Mod)
        {
            answer -= Mod;
        }
        list_1[i] = answer;
    }
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}